

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 参考资料 视频资料 一、预备知识 1.1 序列化定义123序列化就是把内存中的对象，转换成字节序列（或其他数据传输协议）以便于存储到磁盘（持久化）和网络传输。 反序列化就是将收到字节序列（或其他数据传输协议）或者是磁盘的持久化数据，转换成内存中的对象。  1.2 Hadoop序列化的目的12345一般来说，“活的”对象只生存在内存里，关机断电就没有了。而且“活的”对象只能由本地的进程">
<meta property="og:type" content="article">
<meta property="og:title" content="Hadoop _ MapReduce学习笔记（二）Hadoop序列化操作 _ 案例 _ 封装map和reduce操作的value类型">
<meta property="og:url" content="http://example.com/2022/01/20/Hadoop%20_%20MapReduce%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%EF%BC%88%E4%BA%8C%EF%BC%89Hadoop%E5%BA%8F%E5%88%97%E5%8C%96%E6%93%8D%E4%BD%9C%20_%20%E6%A1%88%E4%BE%8B%20_%20%E5%B0%81%E8%A3%85map%E5%92%8Creduce%E6%93%8D%E4%BD%9C%E7%9A%84value%E7%B1%BB%E5%9E%8B/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 参考资料 视频资料 一、预备知识 1.1 序列化定义123序列化就是把内存中的对象，转换成字节序列（或其他数据传输协议）以便于存储到磁盘（持久化）和网络传输。 反序列化就是将收到字节序列（或其他数据传输协议）或者是磁盘的持久化数据，转换成内存中的对象。  1.2 Hadoop序列化的目的12345一般来说，“活的”对象只生存在内存里，关机断电就没有了。而且“活的”对象只能由本地的进程">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/69d7b22263794237999aa9f67ed87d5d.png#pic_center">
<meta property="article:published_time" content="2022-01-20T11:26:23.000Z">
<meta property="article:modified_time" content="2022-08-22T15:44:26.039Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="MapReduce">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/69d7b22263794237999aa9f67ed87d5d.png#pic_center">
  
  
  
  <title>Hadoop _ MapReduce学习笔记（二）Hadoop序列化操作 _ 案例 _ 封装map和reduce操作的value类型 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Hadoop _ MapReduce学习笔记（二）Hadoop序列化操作 _ 案例 _ 封装map和reduce操作的value类型"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-01-20 19:26" pubdate>
          2022年1月20日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.2k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          52 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Hadoop _ MapReduce学习笔记（二）Hadoop序列化操作 _ 案例 _ 封装map和reduce操作的value类型</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h1><hr>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1Qp4y1n7EN?p=81&spm_id_from=pageDriver">视频资料</a></p>
<h1 id="一、预备知识"><a href="#一、预备知识" class="headerlink" title="一、预备知识"></a>一、预备知识</h1><hr>
<h2 id="1-1-序列化定义"><a href="#1-1-序列化定义" class="headerlink" title="1.1 序列化定义"></a>1.1 序列化定义</h2><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs">序列化就是把内存中的对象，转换成字节序列（或其他数据传输协议）以便于存储到磁盘（持久化）和网络传输。 <br><br>反序列化就是将收到字节序列（或其他数据传输协议）或者是磁盘的持久化数据，转换成内存中的对象。<br></code></pre></td></tr></table></figure>

<h2 id="1-2-Hadoop序列化的目的"><a href="#1-2-Hadoop序列化的目的" class="headerlink" title="1.2 Hadoop序列化的目的"></a>1.2 Hadoop序列化的目的</h2><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs">一般来说，“活的”对象只生存在内存里，关机断电就没有了。<br><br>而且“活的”对象只能由本地的进程使用，不能被发送到网络上的另外一台计算机。 <br><br>然而序列化可以存储“活的”对象，可以将“活的”对象发送到远程计算机。<br></code></pre></td></tr></table></figure>

<h2 id="1-3-Hadoop为什么不采用Java原生序列化"><a href="#1-3-Hadoop为什么不采用Java原生序列化" class="headerlink" title="1.3 Hadoop为什么不采用Java原生序列化"></a>1.3 Hadoop为什么不采用Java原生序列化</h2><figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs pgsql">Java的序列化是一个重量级序列化框架（<span class="hljs-keyword">Serializable</span>）<br><br>一个对象被序列化后，会附带很多额外的信息（各种校验信息，<span class="hljs-keyword">Header</span>，继承体系等），不便于在网络中高效传输。<br><br>所以，Hadoop自己开发了一套序列化机制（Writable）。<br></code></pre></td></tr></table></figure>
<h2 id="1-4-Hadoop-序列化特点"><a href="#1-4-Hadoop-序列化特点" class="headerlink" title="1.4 Hadoop 序列化特点"></a>1.4 Hadoop 序列化特点</h2><ul>
<li>紧凑 ：高效使用存储空间。</li>
<li>快速：读写数据的额外开销小。</li>
<li>互操作：支持多语言的交互</li>
</ul>
<h1 id="二、使用案例"><a href="#二、使用案例" class="headerlink" title="二、使用案例"></a>二、使用案例</h1><hr>
<p>需求：统计一个手机耗费的总上行流量、总下行流量、总流量</p>
<p>测试数据：<br><code>phon_data.txt</code></p>
<figure class="highlight basic"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs basic"><span class="hljs-number">1</span>	<span class="hljs-number">13736230513</span>	<span class="hljs-number">192.196</span>.<span class="hljs-number">100.1</span>	www.atguigu.<span class="hljs-keyword">com</span>	<span class="hljs-number">2481</span>	<span class="hljs-number">24681</span>	<span class="hljs-number">200</span><br><span class="hljs-number">2</span>	<span class="hljs-number">13846544121</span>	<span class="hljs-number">192.196</span>.<span class="hljs-number">100.2</span>			<span class="hljs-number">264</span>	<span class="hljs-number">0</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">3 </span>	<span class="hljs-number">13956435636</span>	<span class="hljs-number">192.196</span>.<span class="hljs-number">100.3</span>			<span class="hljs-number">132</span>	<span class="hljs-number">1512</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">4 </span>	<span class="hljs-number">13966251146</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.1</span>			<span class="hljs-number">240</span>	<span class="hljs-number">0</span>	<span class="hljs-number">404</span><br><span class="hljs-symbol">5 </span>	<span class="hljs-number">18271575951</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.2</span>	www.atguigu.<span class="hljs-keyword">com</span>	<span class="hljs-number">1527</span>	<span class="hljs-number">2106</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">6 </span>	<span class="hljs-number">84188413</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.3</span>	www.atguigu.<span class="hljs-keyword">com</span>	<span class="hljs-number">4116</span>	<span class="hljs-number">1432</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">7 </span>	<span class="hljs-number">13590439668</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.4</span>			<span class="hljs-number">1116</span>	<span class="hljs-number">954</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">8 </span>	<span class="hljs-number">15910133277</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.5</span>	www.hao123.<span class="hljs-keyword">com</span>	<span class="hljs-number">3156</span>	<span class="hljs-number">2936</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">9 </span>	<span class="hljs-number">13729199489</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.6</span>			<span class="hljs-number">240</span>	<span class="hljs-number">0</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">10 </span>	<span class="hljs-number">13630577991</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.7</span>	www.shouhu.<span class="hljs-keyword">com</span>	<span class="hljs-number">6960</span>	<span class="hljs-number">690</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">11 </span>	<span class="hljs-number">15043685818</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.8</span>	www.baidu.<span class="hljs-keyword">com</span>	<span class="hljs-number">3659</span>	<span class="hljs-number">3538</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">12 </span>	<span class="hljs-number">15959002129</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.9</span>	www.atguigu.<span class="hljs-keyword">com</span>	<span class="hljs-number">1938</span>	<span class="hljs-number">180</span>	<span class="hljs-number">500</span><br><span class="hljs-symbol">13 </span>	<span class="hljs-number">13560439638</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.10</span>			<span class="hljs-number">918</span>	<span class="hljs-number">4938</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">14 </span>	<span class="hljs-number">13470253144</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.11</span>			<span class="hljs-number">180</span>	<span class="hljs-number">180</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">15 </span>	<span class="hljs-number">13682846555</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.12</span>	www.qq.<span class="hljs-keyword">com</span>	<span class="hljs-number">1938</span>	<span class="hljs-number">2910</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">16 </span>	<span class="hljs-number">13992314666</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.13</span>	www.gaga.<span class="hljs-keyword">com</span>	<span class="hljs-number">3008</span>	<span class="hljs-number">3720</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">17 </span>	<span class="hljs-number">13509468723</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.14</span>	www.qinghua.<span class="hljs-keyword">com</span>	<span class="hljs-number">7335</span>	<span class="hljs-number">110349</span>	<span class="hljs-number">404</span><br><span class="hljs-symbol">18 </span>	<span class="hljs-number">18390173782</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.15</span>	www.sogou.<span class="hljs-keyword">com</span>	<span class="hljs-number">9531</span>	<span class="hljs-number">2412</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">19 </span>	<span class="hljs-number">13975057813</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.16</span>	www.baidu.<span class="hljs-keyword">com</span>	<span class="hljs-number">11058</span>	<span class="hljs-number">48243</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">20 </span>	<span class="hljs-number">13768778790</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.17</span>			<span class="hljs-number">120</span>	<span class="hljs-number">120</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">21 </span>	<span class="hljs-number">13568436656</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.18</span>	www.alibaba.<span class="hljs-keyword">com</span>	<span class="hljs-number">2481</span>	<span class="hljs-number">24681</span>	<span class="hljs-number">200</span><br><span class="hljs-symbol">22 </span>	<span class="hljs-number">13568436656</span>	<span class="hljs-number">192.168</span>.<span class="hljs-number">100.19</span>			<span class="hljs-number">1116</span>	<span class="hljs-number">954</span>	<span class="hljs-number">200</span><br></code></pre></td></tr></table></figure>

<p>输入的数据格式</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">7</span> 	<span class="hljs-number">13560436666</span>	<span class="hljs-number">120.196.100.99</span>		<span class="hljs-number">1116</span>		 <span class="hljs-number">954</span>			<span class="hljs-number">200</span><br><span class="hljs-attribute">id</span>	手机号码		网络ip			上行流量  下行流量     网络状态码<br></code></pre></td></tr></table></figure>

<p>期望输出数据格式：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-number">13560436666</span> 		<span class="hljs-number">1116		      </span><span class="hljs-number">954</span> 			<span class="hljs-number">2070</span><br><span class="hljs-string">手机号码</span>		    <span class="hljs-string">上行流量</span>        <span class="hljs-string">下行流量</span>		<span class="hljs-string">总流量</span><br></code></pre></td></tr></table></figure>

<h2 id="2-1-自定义序列化对象"><a href="#2-1-自定义序列化对象" class="headerlink" title="2.1 自定义序列化对象"></a>2.1 自定义序列化对象</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.writable;<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * Author:      Unirithe/Mr.Chao</span><br><span class="hljs-comment"> * CSDN:        https://blog.csdn.net/Unirithe</span><br><span class="hljs-comment"> * CreatedTime:  2022/1/20 15:36</span><br><span class="hljs-comment"> **/</span><br><br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Writable;<br><br><span class="hljs-keyword">import</span> java.io.DataInput;<br><span class="hljs-keyword">import</span> java.io.DataOutput;<br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 1. 定义类实现 writable 接口</span><br><span class="hljs-comment"> * 2. 重写序列化和反序列化方法</span><br><span class="hljs-comment"> * 3. 重写无参构造</span><br><span class="hljs-comment"> * 4. toString方法</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> */</span><br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FlowBean</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">Writable</span> &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">long</span> upFlow;    <span class="hljs-comment">// 上行流量</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-type">long</span> downFlow;  <span class="hljs-comment">// 下行流量</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-type">long</span> sumFlow;   <span class="hljs-comment">// 总流量</span><br><br>    <span class="hljs-comment">// 无参构造</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-title function_">FlowBean</span><span class="hljs-params">()</span>&#123;&#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">long</span> <span class="hljs-title function_">getUpFlow</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> upFlow;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setUpFlow</span><span class="hljs-params">(<span class="hljs-type">long</span> upFlow)</span> &#123;<br>        <span class="hljs-built_in">this</span>.upFlow = upFlow;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">long</span> <span class="hljs-title function_">getDownFlow</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> downFlow;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setDownFlow</span><span class="hljs-params">(<span class="hljs-type">long</span> downFlow)</span> &#123;<br>        <span class="hljs-built_in">this</span>.downFlow = downFlow;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">long</span> <span class="hljs-title function_">getSumFlow</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> sumFlow;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setSumFlow</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-built_in">this</span>.sumFlow = <span class="hljs-built_in">this</span>.upFlow + <span class="hljs-built_in">this</span>.downFlow;<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">write</span><span class="hljs-params">(DataOutput out)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        out.writeLong(upFlow);<br>        out.writeLong(downFlow);<br>        out.writeLong(sumFlow);<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">readFields</span><span class="hljs-params">(DataInput in)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        <span class="hljs-built_in">this</span>.upFlow = in.readLong();<br>        <span class="hljs-built_in">this</span>.downFlow = in.readLong();<br>        <span class="hljs-built_in">this</span>.sumFlow = in.readLong();<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">toString</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> upFlow + <span class="hljs-string">&quot;\t&quot;</span> + downFlow + <span class="hljs-string">&quot;\t&quot;</span> + sumFlow;<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>
<h2 id="2-2-Mapper阶段"><a href="#2-2-Mapper阶段" class="headerlink" title="2.2 Mapper阶段"></a>2.2 Mapper阶段</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.writable;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.io.LongWritable;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Text;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.Mapper;<br><br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * Author:      Unirithe/Mr.Chao</span><br><span class="hljs-comment"> * CSDN:        https://blog.csdn.net/Unirithe</span><br><span class="hljs-comment"> * CreatedTime:  2022/1/20 15:44</span><br><span class="hljs-comment"> **/</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FlowMapper</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Mapper</span>&lt;LongWritable, Text, Text, FlowBean&gt; &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">Text</span> <span class="hljs-variable">outputKey</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Text</span>();<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">FlowBean</span> <span class="hljs-variable">outputValue</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">FlowBean</span>();<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">map</span><span class="hljs-params">(LongWritable key, Text value, Context context)</span> <span class="hljs-keyword">throws</span> IOException, InterruptedException &#123;<br>        <span class="hljs-comment">// 1.获取一行  7 	13560436666	120.196.100.99		1116		 954			200</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">line</span> <span class="hljs-operator">=</span> value.toString();<br>        <span class="hljs-comment">// 2.切割成 [7,13560436666,120.196.100.99,1116,954,200]</span><br>        String[] split = line.split(<span class="hljs-string">&quot;\t&quot;</span>);<br>        <span class="hljs-comment">// 3. 获取想要的数据: 手机号 13560436666, 上行流量和下行流量: 1116、954</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">phone</span> <span class="hljs-operator">=</span> split[<span class="hljs-number">1</span>];<br>        <span class="hljs-comment">// 顺序的话数据有残缺，故逆序取上行、下行流量</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">up</span> <span class="hljs-operator">=</span> split[split.length - <span class="hljs-number">3</span>];<br>        <span class="hljs-type">String</span> <span class="hljs-variable">down</span> <span class="hljs-operator">=</span> split[split.length - <span class="hljs-number">2</span>];<br><br>        <span class="hljs-comment">// 4. 封装</span><br>        outputKey.set(phone);<br>        outputValue.setUpFlow(Long.parseLong(up));<br>        outputValue.setDownFlow(Long.parseLong(down));<br>        outputValue.setSumFlow();<br>        <span class="hljs-comment">// 5. 写出</span><br>        context.write(outputKey, outputValue);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="2-3-Reducer-阶段"><a href="#2-3-Reducer-阶段" class="headerlink" title="2.3 Reducer 阶段"></a>2.3 Reducer 阶段</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.writable;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.io.LongWritable;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Text;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.Reducer;<br><br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * Author:      Unirithe/Mr.Chao</span><br><span class="hljs-comment"> * CSDN:        https://blog.csdn.net/Unirithe</span><br><span class="hljs-comment"> * CreatedTime:  2022/1/20 15:52</span><br><span class="hljs-comment"> **/</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FlowReducer</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Reducer</span>&lt;Text, FlowBean, Text, FlowBean&gt; &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">FlowBean</span> <span class="hljs-variable">outputValue</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">FlowBean</span>();<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">reduce</span><span class="hljs-params">(Text key, Iterable&lt;FlowBean&gt; values, Context context)</span> <span class="hljs-keyword">throws</span> IOException, InterruptedException &#123;<br>        <span class="hljs-comment">// 1. 遍历集合，累加上下行流量</span><br>        <span class="hljs-type">long</span> <span class="hljs-variable">totalUp</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>        <span class="hljs-type">long</span> <span class="hljs-variable">totalDown</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>        <span class="hljs-keyword">for</span> (FlowBean value : values) &#123;<br>            totalUp += value.getUpFlow();<br>            totalDown += value.getDownFlow();<br>        &#125;<br>        <span class="hljs-comment">// 2. 封装 outputKey，outputValue</span><br>        outputValue.setUpFlow(totalUp);<br>        outputValue.setDownFlow(totalDown);<br>        outputValue.setSumFlow();<br><br>        <span class="hljs-comment">// 3. 写出</span><br>        context.write(key, outputValue);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="2-4-Driver-阶段-运行测试"><a href="#2-4-Driver-阶段-运行测试" class="headerlink" title="2.4 Driver 阶段 + 运行测试"></a>2.4 Driver 阶段 + 运行测试</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.writable;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.conf.Configuration;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.fs.Path;<br><span class="hljs-keyword">import</span> org.apache.hadoop.io.Text;<br><br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.Job;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.lib.input.FileInputFormat;<br><span class="hljs-keyword">import</span> org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;<br><br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * Author:      Unirithe/Mr.Chao</span><br><span class="hljs-comment"> * CSDN:        https://blog.csdn.net/Unirithe</span><br><span class="hljs-comment"> * CreatedTime:  2022/1/20 15:56</span><br><span class="hljs-comment"> **/</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FlowDriver</span> &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException, InterruptedException, ClassNotFoundException &#123;<br>        <span class="hljs-comment">// 1. 创建连接</span><br>        <span class="hljs-type">Configuration</span> <span class="hljs-variable">conf</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Configuration</span>();<br>        <span class="hljs-type">Job</span> <span class="hljs-variable">job</span> <span class="hljs-operator">=</span> Job.getInstance(conf);<br>        <span class="hljs-comment">// 2. 设置jar</span><br>        job.setJarByClass(FlowDriver.class);<br>        <span class="hljs-comment">// 3. 关联 Mapper 、Reducer</span><br>        job.setMapperClass(FlowMapper.class);<br>        job.setReducerClass(FlowReducer.class);<br>        <span class="hljs-comment">// 4. 设置 mapper的输出值 kv类型</span><br>        job.setMapOutputKeyClass(Text.class);<br>        job.setMapOutputValueClass(FlowBean.class);<br>        <span class="hljs-comment">// 5. 设置 最终的输出值 kv类型</span><br>        job.setOutputKeyClass(Text.class);<br>        job.setOutputValueClass(FlowBean.class);<br><br>        <span class="hljs-comment">// 6. 设置数据的输入路径和输出路径</span><br>        FileInputFormat.setInputPaths(job, <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(<span class="hljs-string">&quot;input&quot;</span>));<br>        FileOutputFormat.setOutputPath(job, <span class="hljs-keyword">new</span> <span class="hljs-title class_">Path</span>(<span class="hljs-string">&quot;output&quot;</span>));<br>        <span class="hljs-comment">// 7. 提交Job</span><br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">result</span> <span class="hljs-operator">=</span> job.waitForCompletion(<span class="hljs-literal">true</span>);<br>        System.exit(result ? <span class="hljs-number">0</span> : <span class="hljs-number">1</span>);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><strong>本地运行结果：</strong></p>
<p><img src="https://img-blog.csdnimg.cn/69d7b22263794237999aa9f67ed87d5d.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/" class="category-chain-item">大数据</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/MapReduce/">#MapReduce</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Hadoop _ MapReduce学习笔记（二）Hadoop序列化操作 _ 案例 _ 封装map和reduce操作的value类型</div>
      <div>http://example.com/2022/01/20/Hadoop _ MapReduce学习笔记（二）Hadoop序列化操作 _ 案例 _ 封装map和reduce操作的value类型/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年1月20日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/01/23/Spring%20%E7%AC%94%E8%AE%B03%20Spring%E6%95%B4%E5%90%88MyBatis%E6%A1%86%E6%9E%B6%20_%20Spring%E5%A3%B0%E6%98%8E%E5%BC%8F%E4%BA%8B%E5%8A%A1%E6%8E%A7%E5%88%B6/" title="Spring 笔记3 Spring整合MyBatis框架 _ Spring声明式事务控制">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Spring 笔记3 Spring整合MyBatis框架 _ Spring声明式事务控制</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/01/20/Spring%20%E7%AC%94%E8%AE%B02%20%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5%E7%9A%84%E5%A4%9A%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%9E%84%E9%80%A0%E6%B3%A8%E5%85%A5%E3%80%81p%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%E6%B3%A8%E5%85%A5%E7%AD%89%20_%20AOP%E5%A4%9A%E7%A7%8D%E5%A2%9E%E5%BC%BA%E7%B1%BB%E5%9E%8B%E5%BC%82%E5%B8%B8%E6%8A%9B%E5%87%BA%E5%A2%9E%E5%BC%BA%E3%80%81%E7%8E%AF%E7%BB%95%E5%A2%9E%E5%BC%BA%E7%AD%89%20_%20%E6%B3%A8%E8%A7%A3%E5%BC%80%E5%8F%91%E5%AE%9E%E7%8E%B0%20IoC_DI%20%E5%92%8C%20AOP/" title="Spring 笔记2 依赖注入的多种方式构造注入、p命名空间注入等 _ AOP多种增强类型异常抛出增强、环绕增强等 _ 注解开发实现 IoC_DI 和 AOP">
                        <span class="hidden-mobile">Spring 笔记2 依赖注入的多种方式构造注入、p命名空间注入等 _ AOP多种增强类型异常抛出增强、环绕增强等 _ 注解开发实现 IoC_DI 和 AOP</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
